﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using prjKQXS_DLL;

namespace prjKQXS_Report
{
    public partial class rptHopDong : DevExpress.XtraReports.UI.XtraReport
    {
        public rptHopDong(string Ma_CanBo, string trangthai)
        {
            InitializeComponent();
            Report_DAL report_dal= new Report_DAL();
            this.Ma_CanBo = Ma_CanBo;
            this.trangthai = trangthai;
            loadData(Ma_CanBo,trangthai);
            dsReports1 = report_dal.reportDungChung(dsReports1);

        }
        private SqlConnection conn = new SqlConnection(BienTc.connString);
        private string Ma_CanBo = "", trangthai = "";
        private void loadData(string Ma_CanBo,string trangthai)
        {
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                SqlDataAdapter da=null;
                if (Ma_CanBo == "TC" && trangthai == "TC")
                {
                    da = new SqlDataAdapter(@"Select DMLOAIHOPDONG.Ten_DT as Loai_HD,DMLoaiVe.Ten_DT as Loai_Ve,DMTinhTrang.Ten_DT as Tinh_Trang,HopDong.Ten_CanBo as Ten_DLy,
                 * from HOPDONG LEFT JOIN DMTINHTRANG ON HOPDONG.Ma_DMTinhTrang=DMTINHTRANG.Ma_DT 
                 LEFT JOIN DMLOAIHOPDONG ON HOPDONG.Ma_DMLoaiHD=DMLOAIHOPDONG.Ma_DT LEFT JOIN DMLoaiVe ON HOPDONG.Ma_DMLoaiVe=DMLoaiVe.Ma_DT
                 LEFT JOIN DMCANBO ON HOPDONG.Ma_DMCanBo=DMCANBO.Ma_DT", conn);                    
                }
                else if (Ma_CanBo == "TC")
                {
                    da = new SqlDataAdapter(@"Select DMLOAIHOPDONG.Ten_DT as Loai_HD,DMLoaiVe.Ten_DT as Loai_Ve,DMTinhTrang.Ten_DT as Tinh_Trang,HopDong.Ten_CanBo as Ten_DLy,
                 * from HOPDONG LEFT JOIN DMTINHTRANG ON HOPDONG.Ma_DMTinhTrang=DMTINHTRANG.Ma_DT 
                 LEFT JOIN DMLOAIHOPDONG ON HOPDONG.Ma_DMLoaiHD=DMLOAIHOPDONG.Ma_DT LEFT JOIN DMLoaiVe ON HOPDONG.Ma_DMLoaiVe=DMLoaiVe.Ma_DT
                 LEFT JOIN DMCANBO ON HOPDONG.Ma_DMCanBo=DMCANBO.Ma_DT Where HopDong.isPublic=1 and HopDong.Ma_DMTinhTrang=@tinhtrang", conn);
                    da.SelectCommand.Parameters.AddWithValue("@tinhtrang", trangthai);
                }
                else if (trangthai == "TC")
                {
                    da = new SqlDataAdapter(@"Select DMLOAIHOPDONG.Ten_DT as Loai_HD,DMLoaiVe.Ten_DT as Loai_Ve,DMTinhTrang.Ten_DT as Tinh_Trang,HopDong.Ten_CanBo as Ten_DLy,
                 * from HOPDONG LEFT JOIN DMTINHTRANG ON HOPDONG.Ma_DMTinhTrang=DMTINHTRANG.Ma_DT 
                 LEFT JOIN DMLOAIHOPDONG ON HOPDONG.Ma_DMLoaiHD=DMLOAIHOPDONG.Ma_DT LEFT JOIN DMLoaiVe ON HOPDONG.Ma_DMLoaiVe=DMLoaiVe.Ma_DT
                 LEFT JOIN DMCANBO ON HOPDONG.Ma_DMCanBo=DMCANBO.Ma_DT  where HopDong.isPublic=1 and HopDong.Ma_DMCanBo=@Ma_DMCanBo", conn);
                    da.SelectCommand.Parameters.AddWithValue("@Ma_DMCanBo", Ma_CanBo);
                }
                else
                {
                    da = new SqlDataAdapter(@"Select DMLOAIHOPDONG.Ten_DT as Loai_HD,DMLoaiVe.Ten_DT as Loai_Ve,DMTinhTrang.Ten_DT as Tinh_Trang,HopDong.Ten_CanBo as Ten_DLy,
                 * from HOPDONG LEFT JOIN DMTINHTRANG ON HOPDONG.Ma_DMTinhTrang=DMTINHTRANG.Ma_DT 
                 LEFT JOIN DMLOAIHOPDONG ON HOPDONG.Ma_DMLoaiHD=DMLOAIHOPDONG.Ma_DT LEFT JOIN DMLoaiVe ON HOPDONG.Ma_DMLoaiVe=DMLoaiVe.Ma_DT
                 LEFT JOIN DMCANBO ON HOPDONG.Ma_DMCanBo=DMCANBO.Ma_DT Where HopDong.isPublic=1 and HopDong.Ma_DMCanBo=@Ma_DMCanBo and HopDong.Ma_DMTinhTrang=@tinhtrang", conn);
                    da.SelectCommand.Parameters.AddWithValue("@Ma_DMCanBo", Ma_CanBo);
                    da.SelectCommand.Parameters.AddWithValue("@tinhtrang", trangthai);

                }
                da.Fill(dsReports1.rptHopDong);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }

    }
}
